DECLARE num NUMBER;
BEGIN
SELECT COUNT(1) INTO num FROM USER_TABLES WHERE TABLE_NAME = UPPER('TB_AC_LOG') ;
IF num > 0 THEN
EXECUTE IMMEDIATE 'DROP TABLE TB_AC_LOG' ;
END IF;
END;
/

DECLARE
  C NUMBER;
BEGIN
SELECT COUNT(*) INTO C
FROM ALL_SEQUENCES
  WHERE SEQUENCE_NAME = 'SEQ_TB_AC_LOG_ID';
  IF (C > 0) THEN
    EXECUTE IMMEDIATE 'DROP SEQUENCE SEQ_TB_AC_LOG_ID';
END IF;
END
;
/
CREATE TABLE TB_AC_LOG
(
	id NUMBER(38) NOT NULL,
	client_id VARCHAR2(64) NOT NULL,
	source VARCHAR2(10) NOT NULL,
	ip VARCHAR2(20),
	class_name VARCHAR2(255),
	method VARCHAR2(255),
	remark VARCHAR2(255),
	rq CLOB,
	rs CLOB,
	create_time NUMBER(13) NOT NULL
);

COMMENT ON TABLE TB_AC_LOG IS '统一认证日志'
;

COMMENT ON COLUMN TB_AC_LOG.client_id IS '客户端ID'
;

COMMENT ON COLUMN TB_AC_LOG.source IS '调用来源：rest 或者ams'
;

COMMENT ON COLUMN TB_AC_LOG.ip IS 'IP'
;

COMMENT ON COLUMN TB_AC_LOG.class_name IS '类名'
;

COMMENT ON COLUMN TB_AC_LOG.method IS '方法名'
;

COMMENT ON COLUMN TB_AC_LOG.remark IS '操作说明'
;

COMMENT ON COLUMN TB_AC_LOG.rq IS '请求参数'
;

COMMENT ON COLUMN TB_AC_LOG.rs IS '响应结果'
;

COMMENT ON COLUMN TB_AC_LOG.create_time IS '操作时间'
;



ALTER TABLE TB_AC_LOG
 ADD CONSTRAINT PK_TB_AC_LOG
  PRIMARY KEY (id) USING INDEX
;

CREATE SEQUENCE SEQ_TB_AC_LOG_ID
  INCREMENT BY 1
  START WITH 1
  NOMAXVALUE
  MINVALUE  1
  NOCYCLE
  NOCACHE
  NOORDER
;
CREATE OR REPLACE TRIGGER TRG_TB_AC_LOG_ID
  BEFORE INSERT
  ON TB_AC_LOG
  FOR EACH ROW
  BEGIN
    SELECT SEQ_TB_AC_LOG_ID.NEXTVAL
    INTO :NEW.ID
    FROM DUAL;
  END;
